package com.example.zqm.git72.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.zqm.git72.Activity.SearchTrainActivity;
import com.example.zqm.git72.Adapter.PhotoListAdapter;
import com.example.zqm.git72.Adapter.TrainListAdapter;
import com.example.zqm.git72.JavaBean.Photo;
import com.example.zqm.git72.JavaBean.Train;
import com.example.zqm.git72.Model.PhotoModel;
import com.example.zqm.git72.Model.TrainModel;
import com.example.zqm.git72.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TrainFragment extends Fragment {
    public List<Train> trains;
    private RecyclerView recyclerView;
    private ImageView search;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate( R.layout.fragment_train, container, false);
        recyclerView = (RecyclerView)v.findViewById(R.id.train);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        search=(ImageView)v.findViewById(R.id.search);
        shouData();
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), SearchTrainActivity.class);
                startActivity(intent);
            }
        });
        return v;
    }
    private void shouData() {
        TrainModel trainModel = new TrainModel();
        Call<List<Train>> call = trainModel.getList();
        call.enqueue(new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                trains= response.body();

                recyclerView.setAdapter(new TrainListAdapter(getActivity(), trains));//设置适配器
            }
            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {

            }
        });

    }


}
